


export default {
  gettime: function () {                      //时间轴
    //获取当前时间戳
    var timestamp = Date.parse(new Date());
    timestamp = timestamp / 1000;
    //获取当前时间
    var n = timestamp * 1000;
    var date = new Date(n);
    //年
    var Y = date.getFullYear().toString();
    //月
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1).toString();
    //日
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate().toString();
    //时
    var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours().toString();
    //分
    var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes().toString();
    //秒
    var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds().toString();
    var time_ = Y + M + D + h + m + s;
    //this.globalData.time_ = time_;
    return time_;
  },
  globalData: function () {                            //获取每个接口都需要的appkey
    return 'appKey=fd9c29d4addd0eb08696';
  },
  setlocalstoge: function (key, value) {                //写入本地存储
    value = typeof (value) === 'object' ? JSON.stringify(value) : value;
    window.localStorage.setItem(key, value);
    return true;
  },
  getlocalstoage: function (key) {                     //读取本地存储
    var tem = '';
    try {
      tem = window.localStorage.getItem(key);
      tem = JSON.parse(tem);
    }
    catch (e) { tem = localStorage.getItem(key); }
    return tem;
  },
  remolocalstoage: function (key) {                    //删除本地存储
    window.localStorage.removeItem(key);
    return true;
  },

  displace:function(value,method,item,that){            //判断vuex中state数据的状态 当state中的数据被清空就触发
    if(value === '' || value === null){
      that.$store.commit(method,this.getlocalstoage(item))
    }
  }

}

export function get_request(url, value, that) {                       //封装get请求
  return new Promise((resolve, reject) => {           
    that.$http.get(url, {
      params: value
    }).then(res => {                        
      resolve(res.data);                              //当axios其请求成功时resolve服务器返回值
    }).catch(err => {
      reject(err.data)                                //请求失败时reject错误值
    })
  });
}


export function post_request(url, value,that) {                         //封装post请求
  return new Promise((resolve, reject) => {
    that.$http.post(url, value)
      .then(res => {
        resolve(res.data);                                            //当axios其请求成功时resolve服务器返回值
      })
      .catch(err => {
        reject(err.data)                                            //请求失败时reject错误值
      })
  });
}

